﻿package wn.lizzy.thread;

/**
 * 线程创建方法
 * */
public class Main {

	public static void main(String[] args) {
		
		Thread t = new Thread(new MyRunnable("MyRunnable-2"));
		t.setDaemon(true);
		Thread t2 = new Thread(new MyThread("MyThread-2"));
		
		MyThread mt = new MyThread("");

		t.start();
		t2.start();
		mt.start();
		
		for(int j = 0; j < 1000; j++){
			System.out.println("Main j= " + j);
		}
	}
	
	
}

class MyRunnable implements Runnable{
	
	private String myName = "myRunnabel-1";
	
	public MyRunnable(String _myName){
		if(_myName != "")
			myName = _myName;
	}
	
	public void run() {
		// TODO Auto-generated method stub
		for(int i = 0; i < 100; i++){
			System.out.println(myName + " i = " + i);
		}
	}
	
}

class MyThread extends Thread {
	private String myName = "MyThread-1";
	
	public MyThread(String _myName){
		if(_myName != "")
			myName = _myName;
	}
	public void run() {
		// TODO Auto-generated method stub
		for(int i = 0 ; i < 100; i++){
			System.out.println(myName + " i= " + i);
		}
		
	}
	
} 


